createAccount
Allows you to create a new chart of accounts
/Accounts
Usage and SDK Samples
curl -X "https://api.xero.com/api.xro/2.0/Accounts"
import org.openapitools.client.*;
import org.openapitools.client.auth.*;
import org.openapitools.client.model.*;
import org.openapitools.client.api.AccountingApi;
import java.io.File;
import java.util.*;
public class AccountingApiExample {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure OAuth2 access token for authorization: OAuth2
OAuth OAuth2 = (OAuth) defaultClient.getAuthentication("OAuth2");
OAuth2.setAccessToken("YOUR ACCESS TOKEN");
AccountingApi apiInstance = new AccountingApi();
String xeroTenantId = YOUR_XERO_TENANT_ID; // String | Xero identifier for Tenant
Account account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; // Account |
try {
Accounts result = apiInstance.createAccount(xeroTenantId, account);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AccountingApi#createAccount");
e.printStackTrace();
}
}
}
import org.openapitools.client.api.AccountingApi;
public class AccountingApiExample {
public static void main(String[] args) {
AccountingApi apiInstance = new AccountingApi();
String xeroTenantId = YOUR_XERO_TENANT_ID; // String | Xero identifier for Tenant
Account account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; // Account |
try {
Accounts result = apiInstance.createAccount(xeroTenantId, account);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AccountingApi#createAccount");
e.printStackTrace();
}
}
}
Configuration *apiConfig = [Configuration sharedConfig];
// Configure OAuth2 access token for authorization: (authentication scheme: OAuth2)
[apiConfig setAccessToken:@"YOUR_ACCESS_TOKEN"];
String *xeroTenantId = YOUR_XERO_TENANT_ID; // Xero identifier for Tenant (default to null)
Account *account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; //
AccountingApi *apiInstance = [[AccountingApi alloc] init];
// Allows you to create a new chart of accounts
[apiInstance createAccountWith:xeroTenantId
account:account
completionHandler: ^(Accounts output, NSError* error) {
if (output) {
NSLog(@"%@", output);
}
if (error) {
NSLog(@"Error: %@", error);
}
}];
const tokenSet: TokenSet = {
id_token: 'xxx',
access_token: 'yyy',
expires_at: 1582308862,
token_type: 'Bearer',
refresh_token: 'zzz',
session_state: 'xxx'
}
await xero.setTokenSet(tokenSet);
const xeroTenantId = "YOUR_XERO_TENANT_ID"; // {String} Xero identifier for Tenant
const account: Account = { code: "123456", name: "Foobar", type: AccountType.EXPENSE, description: "Hello World" }
try {
const response = await xero.accountingApi.createAccount(xeroTenantId, account);
console.log(response.body || response.response.statusCode)
} catch (err) {
const error = JSON.stringify(err.response.body, null, 2)
console.log(`Status Code: ${err.response.statusCode} => ${error}`);
}
using System;
using System.Diagnostics;
using .Api;
using .Client;
using .Model;
namespace Example
{
public class createAccountExample
{
public void main()
{
// Configure OAuth2 access token for authorization: OAuth2
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new AccountingApi();
var xeroTenantId = YOUR_XERO_TENANT_ID; // String | Xero identifier for Tenant (default to null)
var account = new Account(); // Account |
try
{
// Allows you to create a new chart of accounts
Accounts result = apiInstance.createAccount(xeroTenantId, account);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling AccountingApi.createAccount: " + e.Message );
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure OAuth2 access token for authorization: OAuth2
$config = XeroAPI\XeroPHP\Configuration::getDefaultConfiguration()->setAccessToken( 'YOUR_ACCESS_TOKEN' );
$config->setHost("https://api.xero.com/api.xro/2.0");
$xeroTenantId = 'YOUR_XERO_TENANT_ID'; // String | Xero identifier for Tenant
$apiInstance = new XeroAPI\XeroPHP\Api\AccountingApi(
new GuzzleHttp\Client(),
$config
);
try {
$account = new XeroAPI\XeroPHP\Models\Accounting\Account;
$account->setCode("987654321");
$account->setName("FooBar");
$account->setType("EXPENSE");
$account->setDescription("Hello World");
$result = $apiInstance->createAccount($xeroTenantId,$account);
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->createAccount: ', $e->getMessage(), PHP_EOL;
}
?>
use Data::Dumper;
use ::Configuration;
use ::AccountingApi;
# Configure OAuth2 access token for authorization: OAuth2
$::Configuration::access_token = 'YOUR_ACCESS_TOKEN';
my $api_instance = ::AccountingApi->new();
my $xeroTenantId = YOUR_XERO_TENANT_ID; # String | Xero identifier for Tenant
my $account = ::Object::Account->new(); # Account |
eval {
my $result = $api_instance->createAccount(xeroTenantId => $xeroTenantId, account => $account);
print Dumper($result);
};
if ($@) {
warn "Exception when calling AccountingApi->createAccount: $@\n";
}
from __future__ import print_statement
import time
import
from .rest import ApiException
from pprint import pprint
# Configure OAuth2 access token for authorization: OAuth2
.configuration.access_token = 'YOUR_ACCESS_TOKEN'
# create an instance of the API class
api_instance = .AccountingApi()
xeroTenantId = YOUR_XERO_TENANT_ID # String | Xero identifier for Tenant (default to null)
account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" } # Account |
try:
# Allows you to create a new chart of accounts
api_response = api_instance.create_account(xeroTenantId, account)
pprint(api_response)
except ApiException as e:
print("Exception when calling AccountingApi->createAccount: %s\n" % e)
extern crate AccountingApi;
pub fn main() {
let xeroTenantId = YOUR_XERO_TENANT_ID; // String
let account = { "Code":"123456", "Name":"Foobar", "Type":"EXPENSE", "Description":"Hello World" }; // Account
let mut context = AccountingApi::Context::default();
let result = client.createAccount(xeroTenantId, account, &context).wait();
println!("{:?}", result);
}
Scopes
| accounting.settings | Grant read-write access to organisation and account settings |
Parameters
| Name | Description |
|---|---|
| xero-tenant-id* |
String
Xero identifier for Tenant
Required
|
| Name | Description |
|---|---|
| account * |
Account
Account object in body of request
Required
|